package com.example.cash.craft.dao.persist.repository.impl;

import com.example.cash.craft.dao.persist.mapper.OrderMapper;
import com.example.cash.craft.dao.persist.repository.IOrderRepository;
import com.example.cash.craft.pojo.entity.Order;
import com.example.cash.craft.pojo.vo.OrderSimpleInfoVO;
import com.example.cash.craft.pojo.vo.PageData;
import com.example.cash.craft.util.PageInfoToPageDataConverter;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderRepositoryImpl implements IOrderRepository {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public int insert(Order order) {
        return orderMapper.insert(order);
    }

    @Override
    public OrderSimpleInfoVO selectById(Long id) {
        return orderMapper.selectById(id);
    }

    @Override
    public PageData<OrderSimpleInfoVO> listByUserId(Long userId, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<OrderSimpleInfoVO> list = orderMapper.listByUserId(userId);
        PageInfo<OrderSimpleInfoVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

}
